30.2.2. MongoDBTemplate

Spring Data Mongo提供了一个MongoTemplate类,它的设计和Spring的JdbcTemplate很相似。跟JdbcTemplate一样,Spring Boot会为你自动配置一个bean,你只需简单的注入即可:

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Component;

@Component
public class MyBean {

    private final MongoTemplate mongoTemplate;

    @Autowired
    public MyBean(MongoTemplate mongoTemplate) {
        this.mongoTemplate = mongoTemplate;
    }
    // ...
}

具体参考MongoOperations Javadoc。

powered by Gitbook该页面构建时间: 2017-08-01 08:30:16

results matching ""

    No results matching ""